package ooday03;

/*引用类型数组的演示*/
public class RefArrayDemo {
    public static void main(String[] args) {
        //声明Dog型数组dogs，包含3个元素，每个元素都是Dog型，默认值为null
       /* Dog[] dogs=new Dog[3];
        Chick[] chicks=new Chick[3];
        Fish[] fish =new Fish[2];*/
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑");//给引用类型赋值一定要new个对象
        dogs[1] = new Dog("小白", 2, "灰");
        dogs[2] = new Dog("小灰", 3, "绿");
        dogs[1].age = 4;//修改第2只狗狗的年龄为4岁
        System.out.println(dogs[0].name);//输出第一只狗的名字
        dogs[2].swim();//第三只狗在游泳

        for (int i=0;i< dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }
        /*Dog d = null;//引用类型默认值为null
        int a = null;//编译错误*/
        //创建Dog对象
        // 给引用类型数组的元素赋值时，需要new个对象
        //访问引用类型数组元素的属性/行为时，需要打点访问
        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小花", 1, "花");
        chicks[1] = new Chick("大花", 2, "花");
       for (int i=0;i< chicks.length;i++){
           System.out.println(chicks[i].name);
           chicks[i].LayEggs();
       }
    }
}
